package com.spring.oaassist.web.service.impl;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.spring.oaassist.web.dao.ProtalMapper;
import com.spring.oaassist.web.model.XsyjData;
import com.spring.oaassist.web.service.ProtalService;
import com.spring.security.core.util.ApplicationUtils;

@Service
public class ProtalServiceImpl implements ProtalService{
	
	@Resource ProtalMapper protalMapper;

	@Override
	public List<Map<String, Object>> queryRdkhList(Map<String, Object> parm) {
		return protalMapper.queryRdkhList(parm);
	}

	@Override
	public List<Map<String, Object>> queryXsfyList(Map<String, Object> parm) {
		return protalMapper.queryXsfyList(parm);
	}

	@Override
	public List<Map<String, Object>> queryRcList(Map<String, Object> parm) {
		return protalMapper.queryRcList(parm);
	}

	@Override
	public List<Map<String, Object>> queryJnrList(Map<String, Object> parm) {
		return protalMapper.queryJnrList(parm);
	}

	@Override
	public List<Map<String, Object>> queryKhtsList(Map<String, Object> parm) {
		return protalMapper.queryKhtsList(parm);
	}

	
	@Override
	public Map<String, Object> queryXsyjData(Map<String, Object> parm) {
		Map<String,Object> retMap = Maps.newHashMap();
		
		//签约客户数
		List<XsyjData> xsyjList1 =  protalMapper.queryXsyjQysList(parm);
		retMap.put("qykhs_sj", xsyjList1.size());
		
		//新增客户数
		List<XsyjData> xsyjList2 =  protalMapper.queryXsyjKhsList(parm);
		retMap.put("xzkhs_sj", xsyjList2.size());
		
		//实际签约额
		Map<String, Object> xseMap = protalMapper.queryXsyjAmount(parm);
		double xse = Double.parseDouble(ApplicationUtils.Object2String(xseMap.get("amount")));
		retMap.put("xse_sj", xse);
		
		//1:签约额  2:客户数
		Double mbwce = 0.00;
		List<Map<String, Object>> targetList = protalMapper.queryXsyjTarget(parm);
		for(Map<String, Object> tar:targetList){
			if("1".equals(ApplicationUtils.Object2String(tar.get("saleTargetType")))){//目标签约额
				retMap.put("xse_mb", tar.get("amount"));
				mbwce = Double.parseDouble(ApplicationUtils.Object2String(tar.get("amount")));
			}
			if("2".equals(ApplicationUtils.Object2String(tar.get("saleTargetType")))){//目标客户数
				retMap.put("xzkhs_mb", tar.get("amount"));
			}
		}
		//实际完成百分比
		DecimalFormat df = new DecimalFormat("#0.00");
		retMap.put("xse_wcd", mbwce==0?"100%":(df.format(xse/mbwce*100)+"%"));
		return retMap;
	}

	@Override
	public List<Map<String,Object>> queryKcsxData(Map<String, Object> parm) {
		return protalMapper.queryKcsxData(parm);
	}

	@Override
	public List<Map<String,Object>> queryKcxxData(Map<String, Object> parm) {
		return protalMapper.queryKcxxData(parm);
	}

	@Override
	public List<Map<String, Object>> queryKczcList(Map<String, Object> parm) {
		return protalMapper.queryKczcList(parm);
	}

}
